<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>沛桐鞋业oa系统</title>
    <meta name="description" content="沛桐鞋业">
    <meta name="keywords" content="沛桐鞋业">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../../plugins/elementui/index.css">
    <link rel="stylesheet" href="../../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../../css/style.css">
    <style>
        .el-dropdown-link {
            cursor: pointer;
            color: #409EFF;
        }

        .el-icon-arrow-down {
            font-size: 12px;
        }
    </style>

</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>员工管理
            <small>{{grade==1?"生产":"月薪"}}员工信息管理</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>员工管理</el-breadcrumb-item>
            <el-breadcrumb-item >{{grade==1?"生产":"月薪"}}员工信息管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="员工工号/员工姓名" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item"></el-input>
                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                <el-upload :action="action"
                           name="excelFile"
                           :show-file-list="false"
                           :on-success="handleSuccess"
                           :before-upload="beforeUpload"
                           style="float: right">
                    <el-button type="primary">上传文件</el-button>
                </el-upload>
                <el-select v-if="showPrise" v-model="value" placeholder="可选择部门查询" @change="choose()">
                    <el-option
                            v-for="item in options"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </div>

            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="code" label="工号" align="center"></el-table-column>
                <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                <el-table-column label="性别" align="center">
                    <template slot-scope="scope">
                        <span>{{ scope.row.sex == '0' ? '男' : '女'}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="department" label="部门" align="center"></el-table-column>
                <el-table-column prop="position" label="职位" align="center"></el-table-column>
                <el-table-column prop="phonenumber" label="手机号码" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="goDetail(scope.row)">详细信息</el-button>
                        <el-button size="mini" type="danger"  @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog :title="title" :visible.sync="dialogFormVisible">
                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="员工编码" prop="code">
                                    <el-input v-model="formData.code"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="部门">
                                    <el-input v-model="formData.department"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="员工名称" prop="name">
                                    <el-input v-model="formData.name"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="性别">
                                    <el-select v-model="formData.sex">
                                        <el-option label="男" value="0"></el-option>
                                        <el-option label="女" value="1"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="职位">
                                    <el-input v-model="formData.position"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="身份证号">
                                    <el-input v-model="formData.idcard"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="联系电话">
                                    <el-input v-model="formData.phonenumber"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="家人电话">
                                    <el-input v-model="formData.family_phone"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="地址">
                                    <el-input v-model="formData.address"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="现居住地址">
                                    <el-input v-model="formData.current_address"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="入职日期">
                                    <el-date-picker
                                            v-model="formData.hiredate"
                                            type="date"
                                            placeholder="选择日期">
                                    </el-date-picker>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="备注">
                                    <el-input v-model="formData.remaks"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../../js/vue.js"></script>
<script src="../../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../../js/jquery.min.js"></script>
<script src="../../js/axios-0.18.0.js"></script>
<script>
    var grade = window.location.href.split("=")[1];
    var vue = new Vue({
            el: '#app',
            data: {
                grade: null,
                showPrise: true,
                options: [{
                    value: '针一组',
                    label: '针一组'
                }, {
                    value: '针二组',
                    label: '针二组'
                }, {
                    value: '针三组',
                    label: '针三组'
                }, {
                    value: '针五组',
                    label: '针五组'
                }, {
                    value: '针六组',
                    label: '针六组'
                }, {
                    value: '针七组',
                    label: '针七组'
                }, {
                    value: '成一组',
                    label: '成一组'
                }, {
                    value: '成二组',
                    label: '成二组'
                }, {
                    value: '裁断组',
                    label: '裁断组'
                }, {
                    value: '电脑班',
                    label: '电脑班'
                }, {
                    value: '品管部',
                    label: '品管部'
                }, {
                    value: '包装组',
                    label: '包装组'
                },],
                value: "",
                action: "",
                pagination: {//分页相关模型数据
                    currentPage: 1,//当前页码
                    pageSize: 10,//每页显示的记录数
                    total: 0,//总记录数
                    queryString: null//查询条件
                },
                title: "",
                dataList: [],//当前页要展示的分页列表数据
                formData: {},//表单数据
                dialogFormVisible: false,//增加表单是否可见
                dialogFormVisible4Edit: false,//编辑表单是否可见
                rules: {//校验规则
                    code: [{required: true, message: '员工编码为必填项', trigger: 'blur'}],
                    name: [{required: true, message: '员工姓名为必填项', trigger: 'blur'}]
                }
            },
            //钩子函数，VUE对象初始化完成后自动执行
            created() {
                this.findPage();
                this.action = grade == 1 ? "/staff/upload_staff.do" : "/staff/upload.do";
                this.showPrise = grade == 1 ? true : false;
            },
            mounted() {
            this.grade = window.location.href.split("=")[1];
            this.grade_name=grade==1?"月薪":"生产";
        },
            methods: {
                //跳转详细信息页面
                goDetail(e){
                    window.location.href="staff_detail.html?id="+e.id;
                },
                //选择部门后执行
                choose() {
                    this.pagination.currentPage = 1;
                    this.findPage();
                },
                //上传成功提示
                handleSuccess(response, file) {

                    if (response.flag) {
                        this.$message({
                            message: response.message,
                            type: 'success'
                        });
                        location.reload();
                    } else {
                        this.$message.error(response.message);
                    }
                    console.log(response, file, fileList);
                },
                //上传之前进行文件格式校验
                beforeUpload(file) {
                    let fileName = file.name.split('.');
                    if (fileName[fileName.length - 1] === "xlsx" ||
                        fileName[fileName.length - 1] === "xls" ||
                        fileName[fileName.length - 1] === "xltx" ||
                        fileName[fileName.length - 1] === "xlt" ||
                        fileName[fileName.length - 1] === "xlsm" ||
                        fileName[fileName.length - 1] === "xlsb" ||
                        fileName[fileName.length - 1] === "xltm" ||
                        fileName[fileName.length - 1] === "csv"
                    ) {
                        return true
                    } else {
                        this.$message('请上传正确格式的表格');
                        return false;
                    }
                },
                //权限不足提示
                showMessage(r) {
                    if (r == 'Error: Request failed with status code 403') {
                        //权限不足
                        this.$message.error('无访问权限');
                        return;
                    } else {
                        this.$message.error('未知错误');
                        return;
                    }
                },
                //编辑
                handleEdit() {
                },
                //添加
                handleAdd() {
                    //进行表单校验
                    this.formData.grade = this.grade;
                    this.$refs['dataAddForm'].validate((valid) => {
                        if (valid) {
                            //如果校验通过，发送ajax请求，将表单数据提交到Controller
                            axios.post("/staff/add.do?", this.formData).then((res) => {
                                if (res.data.flag) {
                                    //处理成功
                                    this.$message({
                                        type: 'success',
                                        message: res.data.message
                                    });
                                    //关闭新增窗口
                                    this.dialogFormVisible = false;
                                    //分页查询
                                    this.findPage();
                                } else {
                                    //处理失败
                                    this.$message.error(res.data.message);
                                }
                            }).catch((r) => {
                                this.showMessage(r);
                            });
                        } else {
                            //校验不通过，提示错误信息
                            this.$message.error("表单数据校验失败，请检查输入是否正确！");
                        }
                    });
                },
                //分页查询
                findPage() {
                    let param = {
                        currentPage: this.pagination.currentPage,//当前页码
                        pageSize: this.pagination.pageSize,//每页显示的记录数
                        queryString: this.pagination.queryString,//查询条件
                        department: this.value//分部门查询条件
                    };
                    axios.post(grade == 1 ? "/staff/show_staff.do" : "/staff/show.do", param).then((resp) => {
                        this.dataList = resp.data.rows;
                        this.pagination.total = resp.data.total;
                    })
                    /*.catch((r) => {
                                            this.showMessage(r);
                                        })*/
                },
                // 重置表单
                resetForm() {
                    this.formData = {};
                },
                // 弹出添加窗口
                handleCreate() {
                    this.title = "新增检查项";
                    this.resetForm();
                    this.dialogFormVisible = true;
                },
                //切换页码
                handleCurrentChange(currentPage) {
                    this.pagination.currentPage = currentPage;
                    this.findPage();
                },
                // 删除
                handleDelete(row) {
                    this.$confirm('是否删除该项目', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        axios.delete("/staff/delete.do?id=" + row.id).then((resp) => {
                            if (resp.data.flag) {
                                this.$message({
                                    type: 'success',
                                    message: resp.data.message
                                });
                            } else {
                                this.$message.error(resp.data.message);
                            }

                        }).catch((r) => {
                            this.showMessage(r);
                        }).finally(() => {
                            this.findPage();
                        })
                    });
                }
            }
        }
    )
</script>
</html>